﻿function BindSelect(ctrlName, url) {
    $.getJSON(url, function (data) {
        var control = $('#' + ctrlName);
        control.empty();//清空下拉框
        control.append("<option value=''>请选择</option>");
        $.each(data, function (i, item) {
            for (var j = 0; j < item.length; j++) {
                control.append("<option value='"+ item[j].id +"'>" + item[j].text + "</option>");
            }
        });

        control.select2();
    });
}

function BindSelectByValue(ctrlName, url, val) {
    $.getJSON(url, function (data) {
        var control = $('#' + ctrlName);
        control.empty();//清空下拉框
        control.append("<option value=''>请选择</option>");
        $.each(data, function (i, item) {
            for (var j = 0; j < item.length; j++) {
                if (item[j].id == val) {
                    control.append("<option value='" + item[j].id + "' selected='selected'>" + item[j].text + "</option>");
                }
                else {
                    control.append("<option value='" + item[j].id + "'>" + item[j].text + "</option>");
                }
               
            }
        });

        control.select2();
    });
}


function BindSelectValue(ctrlName, url, str) {
    $.getJSON(url, function (data) {
      
        var control = $('#' + ctrlName);
        control.empty();//清空下拉框
        $.each(data, function (i, item) {
            for (var j = 0; j < item.length; j++) {
              
                if (str.indexOf(item[j].id)) {
                    control.append("<option value='" + item[j].id + "' selected='selected' >" + item[j].text + "</option>");
                }
                else {
                    control.append("<option value='" + item[j].id + "'>" + item[j].text + "</option>");
                }
               
            }
        });

        control.select2();
    });
}


//绑定字典内容到指定的控件
//function BindDictItem(ctrlName, dictTypeName) {
//    var url = '/DictData/GetDictJson?dictTypeName=' + encodeURI(dictTypeName);
//    BindSelect(ctrlName, url);
//}

